'''用的时候要慎重，会先删除文件'''
import os
input_dir='/home/xys/CloundShiProjects/traffic_light/trafficlight_dect/data/xml/'

filenames = os.listdir(input_dir)
for filename in filenames:
    path = input_dir+filename
    file_front = filename[:-4]
    with open(path, mode='r', errors='ignore') as f:
        lines = f.readlines()
        f.close()
    lines[2]='   <filename>'+file_front+'</filename>\n'
    with open(path, mode='w', errors='ignore') as f:
        for line in lines:
            f.write(line)
        f.close()